<div class="form-wrapper">
	<div class="form-header"><?php echo lang('student_add_header'); ?></div>
	<?php if (validation_errors()): ?>
	<div class="error-box">
		<?php echo validation_errors('<div>','</div>');?>
	</div>
	<?php endif; ?>
    
	<?php echo form_open(site_url('grading/students/create')); ?>
	<label for="student_number"><?php echo lang('student_number'); ?></label>
	<input type="text" maxlength="10" autocomplete="off" class="ipt-txt half-width" name="number" value="<?php echo set_value('number'); ?>" />
	<br/>
	<label for="student_fname"><?php echo lang('student_fname'); ?></label>
	<input type="text" maxlength="30" autocomplete="off" class="ipt-txt full-width" name="firstName" value="<?php echo set_value('firstName');?>" />
	<br/>
	<label for="student_mname"><?php echo lang('student_mname'); ?></label>
	<input type="text" maxlength="30" autocomplete="off" class="ipt-txt full-width" name="middleName" value="<?php echo set_value('middleName');?>" />
	<br/>
	<label for="student_lname"><?php echo lang('student_lname'); ?></label>
	<input type="text" maxlength="30" autocomplete="off" class="ipt-txt full-width" name="lastName" value="<?php echo set_value('lastName');?>" />
	
	<table class="table-grid" id="item-grid">
            <thead>
		<tr>
                    <th><?php echo lang('student_item'); ?></th>
                    <th><?php echo lang('student_item_amount'); ?></th>
                    <th class="action-width"></th>
                </tr>
            </thead>
            <tbody>
                
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="2"></td>
                    <td class="align-center" ><a href="#" class="btn btn-add"><span class="btn-icon plus-icon"></span><?php echo lang('student_button_add_item'); ?></a></td>
                </tr>
            </tfoot>
	</table>
	
	<fieldset id="action">
		<a href="#" class="btn btn-save"><span class="btn-icon disk-icon"></span><?php echo lang('student_button_save'); ?></a>
		<a href="<?php echo site_url('grading/students'); ?>" class="btn btn-cancel"><span class="btn-icon cancel-icon"></span><?php echo lang('student_button_cancel'); ?></a>
	</fieldset>
    <?php echo form_close(); ?>
</div>
<script>

        var item = '';
        var counter = 0;
        <?php foreach ( $item as $i ) : ?>
            item += "<option value='<?php echo $i->id; ?>'><?php echo $i->name; ?></option>";                   
        <?php endforeach; ?>
        
	$('.btn-save').click(function(){
		$('form').submit();
		return false;
	});
        
        $('.btn-add').click(function(){
           
           $('#item-grid tbody').append(
                $('<tr>').attr('id','tr_'+(++counter)).append(
                    $('<td>').append(
                        $('<select>').addClass('max-width item-select').attr('name','student_items[]').append(
                            item
                        )
                    ),
                    $('<td>').append(
                        $('<input type="text">').attr('name','item_amount[]')
                    ),
                    $('<td>').append(
                        $('<a>').addClass('btn btn-delete').append(
                            $('<span>').addClass('btn-icon delete-icon'),
                            'Remove'
                        ).attr({'title':'Remove','href':'#','rel':'tr_'+counter}).bind('click',function(){
                            $('#'+$(this).attr('rel')).remove();
                        })
                    )
                )
           );
            return false;
        });
        
</script>